@Service
public class UserService {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Transactional(
        propagation = Propagation.REQUIRED, 
        isolation = Isolation.DEFAULT,     
        rollbackFor = Exception.class     
    )
    public void transferMoney(String from, String to, BigDecimal amount) {
        // 扣款操作
        jdbcTemplate.update(
            "UPDATE account SET balance = balance - ? WHERE username = ?",
            amount, from);
        
      
        if(amount.compareTo(BigDecimal.ZERO) < 0){
            throw new IllegalArgumentException("金额不能为负数");
        }
        
      
        jdbcTemplate.update(
            "UPDATE account SET balance = balance + ? WHERE username = ?",
            amount, to);
    }
}